package com.example.taluo.utils;

public class EloCalculator {
    private static final int K_FACTOR = 32;

    public static EloResult calculate(int winnerElo, int loserElo){
        double qWinner = Math.pow(10, winnerElo / 400.0);
        double qLoser = Math.pow(10, loserElo / 400.0);

        double expectedWinner = qWinner / (qWinner + qLoser);
        double expectedLoser = qLoser / (qWinner + qLoser);

        int newWinnerElo = (int)(winnerElo + K_FACTOR * (1 - expectedWinner));
        int newLoserElo = (int)(loserElo + K_FACTOR * (0 - expectedLoser));

        return new EloResult(newWinnerElo, newLoserElo);
    }

    public static class EloResult{
        public final int winnerNewELo;
        public final int loserNewElo;

        EloResult(int winnerNewELo, int loserNewElo){
            this.winnerNewELo = winnerNewELo;
            this.loserNewElo = loserNewElo;
        }
    }
}
